import 'package:flutter/material.dart';

class BottomNavigationBarApp extends StatelessWidget
{
      @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new MaterialApp(
              title: 'BottomNavigationBarApp',
              home: new Scaffold(
                      body: new MyHomePage(),
              ),
    );
  }
}

class MyHomePage extends StatefulWidget
{
  MyHomePage({Key key}):super(key:key);

    @override
    _MyHomePageState createState() {
    // TODO: implement createState
    return _MyHomePageState();
  }
}

class _MyHomePageState extends State<MyHomePage>
{
    int _selectIndex=1;//当前选中索引
    final _widgetOptionas=[
          Text('Index 0: 信息'),
          Text('Index 1: 通讯录'),
          Text('Index 2: 发现'),];
    @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return  new Scaffold(
              appBar: AppBar(title: new Text('BottomNavigationBarApp demo示例'),),
              body: Center(
                      child: _widgetOptionas.elementAt(_selectIndex),//居中显示某一个文本
              ),
              //底部导航栏按钮，包含图标和文本
              bottomNavigationBar: BottomNavigationBar(items: <BottomNavigationBarItem>[
                                      BottomNavigationBarItem(icon: Icon(Icons.chat,),title: new Text('信息')),
                                      BottomNavigationBarItem(icon: Icon(Icons.contacts,),title: new Text('通讯录')),
                                      BottomNavigationBarItem(icon: Icon(Icons.account_circle,),title: new Text('发现')),
              ],
                currentIndex: _selectIndex,//当前选中项索引
                fixedColor: Colors.deepPurple,//选项中项的颜色
                onTap: _onItemTapped,//选择按下出处理
              ),
    );
  }
  //选择按下处理，设置当前索引为index值
  void _onItemTapped(int index)
  {
      setState(() {
            _selectIndex=index;
      });
  }
}